<?php
declare (strict_types=1);

namespace app\advertiser\controller;

use app\advertiser\service\AdvertiserUserService;
use app\BaseController;
use think\facade\Request;
use think\response\Json;
use upload\ImgUpload;

/**
 * 广告主用户管理
 */
class AdvertiserUser extends BaseController
{

    /**
     * 广告主图片文件上传
     * @return Json
     */
    public function adFileUploadImg(): Json
    {
        $file = request()->file('picture');
        if (!$file) {
            return jsonReturn(0, [], '图片参数错误');
        }
        //处理上传图片信息
        $picture = ImgUpload::imgUploadAliyun($file, 'advertiser/picture', 0, 0, 1000);
        return jsonReturn(1, $picture, '上传成功');
    }

    /**
     * 广告主注册
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function adUserAdd(AdvertiserUserService $advertiserUserService): Json
    {
        $params['phone'] = Request::param('phone/s', '');
        $params['password'] = Request::param('password/s', '');
        $params['name'] = Request::param('name/s', '');
        $params['code'] = Request::param('code/s', '');
        return $advertiserUserService->adUserAdd($params);
    }

    /**
     * 获取验证码
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function adUserCode(AdvertiserUserService $advertiserUserService): Json
    {
        $params['phone'] = Request::param('phone/s', '');
        return $advertiserUserService->adUserCode($params);
    }

    /**
     * 广告主登录
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function adUserLogin(AdvertiserUserService $advertiserUserService): Json
    {
        $params['phone'] = Request::param('phone/s', '');
        $params['password'] = Request::param('password/s', '');
        return $advertiserUserService->adUserLogin($params);
    }

    /**
     * 广告主找回密码
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function adUserPwd(AdvertiserUserService $advertiserUserService): Json
    {
        $params['phone'] = Request::param('phone/s', '');
        $params['password'] = Request::param('password/s', '');
        $params['code'] = Request::param('code/s', '');
        return $advertiserUserService->adUserPwd($params);
    }

    /**
     * 广告主修改密码
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function adUserEditPwd(AdvertiserUserService $advertiserUserService): Json
    {
        $params['old_password'] = Request::param('old_password/s', '');
        $params['new_password'] = Request::param('new_password/s', '');
        return $advertiserUserService->adUserEditPwd($params);
    }


}
